import { Controller, Get, Post, Body, Delete, Query } from '@nestjs/common';

import { UpdatePasswordDto } from './dto/update-password.dto';
import { UpdateUserDto } from './dto/update-user.dto';

import { UserService } from './user.service';
import { RequireLogin } from 'src/decorators/custom.decorator';
import { ListUserDto } from './dto/list-user.dto';

@Controller('user')
@RequireLogin()
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get('initData')
  async initData() {
    await this.userService.initData();
  }

  @Get('list')
  async getUserList(@Query() query: ListUserDto) {
    return this.userService.getUserList(query);
  }

  @Get('detail')
  async getUserDetail(@Query('id') id: number) {
    return this.userService.getUserDetail(id);
  }

  @Delete('del')
  async deleteUser(@Body() body: { id: number }) {
    return this.userService.deleteUser(body.id);
  }

  @Post('updatePwd')
  async updatePassword(@Body() updatePasswordDto: UpdatePasswordDto) {
    return this.userService.updatePassword(
      updatePasswordDto.id,
      updatePasswordDto.password,
    );
  }

  @Post('update')
  async updateUser(@Body() updateUserDto: UpdateUserDto) {
    return this.userService.updateUser(updateUserDto);
  }
}
